import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'


import Main from '../views/Main.vue'

import CategoriesCreate from '../views/Categories/Create.vue'
import CategoriesList from '../views/Categories/List.vue'
import ItemsCreate from '../views/Items/Create.vue'
import ItemsList from '../views/Items/List.vue'
import HeroesCreate from '../views/Heroes/Create.vue'
import HeroesList from '../views/Heroes/List.vue'
import NewsCreate from '../views/News/Create.vue'
import NewsList from '../views/News/List.vue'
import AdminUsersCreate from '../views/AdminUsers/Create.vue'
import AdminUsersList from '../views/AdminUsers/List.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/Login',
    name: 'Login',
    component: Login,
    meta: { isPublic: true }
  },
  {
    path: '/',
    name: 'Main',
    redirect: '/Login',
    component: Main,
    children: [
      {
        path: '/categories/create',
        name: 'categoriesCreate',
        component: CategoriesCreate
      },
      {
        path: '/categories/list',
        component: CategoriesList
      },
      {
        path: '/items/create',
        name: 'itemsCreate',
        component: ItemsCreate
      },
      {
        path: '/items/list',
        component: ItemsList
      },
      {
        path: '/heroes/create',
        name: 'heroesCreate',
        component: HeroesCreate
      },
      {
        path: '/heroes/list',
        component: HeroesList
      },
      {
        path: '/news/create',
        name: 'newsCreate',
        component: NewsCreate
      },
      {
        path: '/news/list',
        component: NewsList
      },
      {
        path: '/admin_users/create',
        name: 'adminUsersCreate',
        component: AdminUsersCreate
      },
      {
        path: '/admin_users/list',
        component: AdminUsersList
      },


    ]
  },

]

const router = new VueRouter({
  routes
})

// 这个方法不好，不能重定位，如果路径是/就不显示任何东西
// router.beforeEach((to, from, next) => {
//   if ( to.meta && !to.meta.isPublic && !sessionStorage.token) {
//     return next('/Login')
//   }
//   next()

// })

export default router
